// ActionScript file

import flash.events.MouseEvent;
import flash.utils.setTimeout;

import model.PropertyInfo;
import model.User;

import mx.controls.Alert;

//取消登录的请求
public function cacelLoginIn():void
{
}

//发起登录的请求
public function loginIn(event:MouseEvent):void
{
	var passport:String=userNameLogin.text;
	var password:String=userPwdLogin.text;
	var user:User=new User();
	user.passport=passport;
	user.password=password;
//	var array:Array = new Array();
//	array.push(1);
//	array.push("asdfasdf");
	var propertyInfo:PropertyInfo=new PropertyInfo();
	propertyInfo.errorCode=1;
	propertyInfo.data=user;
	propertyInfo.eventType="login";
//  propertyInfo.dataFuncName="loginInData";
//	propertyInfo.dataProperties = array;
	sendSocketByData(propertyInfo);
}

public function moveObj(event:MouseEvent):void
{
	Alert.show("asdfas");
}

//登录请求的回调函数
public function loginInData(data:PropertyInfo, type:Number, value:String):void
{
	var m:MouseEvent=new MouseEvent(MouseEvent.DOUBLE_CLICK);
	this.dispatchEvent(m);
	Alert.show(type + ":" + value);
}

//切换到注册模块
public function viewRegister():void
{
	hideAndShow(loginForm, registerForm);
}

//注册用户
public function registerIn():void
{
	var registerName:String=userNameRegister.text;
	var registerPwd:String=userPwdRegister.text;
	var registerPwdRe:String=userPwdRegisterRe.text;
	if (registerName == null || registerName == "")
	{
		Alert.show("注册用户名不能为空");
		return;
	}
	if (registerPwd == null || registerPwd == "")
	{
		Alert.show("密码不能为空");
		return;
	}
	if (registerPwdRe == null || registerPwdRe == "")
	{
		Alert.show("重复密码不能为空");
		return;
	}
	if (registerPwdRe != registerPwd)
	{
		Alert.show("两次密码必须输入一致");
		return;
	}
	var user:User=new User();
	user.passport=registerName;
	user.password=registerPwd;
	var propertyInfo:PropertyInfo=new PropertyInfo();
	propertyInfo.errorCode=1;
	propertyInfo.eventType="registerInData";
	propertyInfo.data=user;
	sendSocketByData(propertyInfo);
}

public function registerInData(propertyInfo:PropertyInfo):void
{

}

//切换到登录页面
public function viewLogin():void
{
	hideAndShow(registerForm, loginForm);
}

public function hideAndShow(hideEles:Object, showEles:Object):void
{
	hideEle(hideEles);
	setTimeout(showEle, 1000, showEles);
}

public function showEle(ele:Object):void
{
	ele.visible=true;
}

public function hideEle(ele:Object):void
{
	ele.visible=false;
}